<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php 
	$ci = &get_instance();
	$this->load->helper('captcha');
	
?>
<form action="<?php echo site_url('cricket/user/forgot_details_submit');?>" name="forgot_details_submit" id="forgot_details_submit" method="post" enctype="multipart/form-data" >
<div id="center_content">
	<div class="clrboth"></div>
	<div class="block">
		<div class="title"><h3 class="bold">User Forgot Details</h3></div>
		<div class="clrboth"></div>
		<div class="content">
			<div class="rowitem3">
				<div class="grid2">&nbsp;</div>
				<div class="grid6" style="padding-left:5px;">Enter your email account which you used for registration to get back information.</div>
				
				<div class="clrboth"></div>
				<div class="grid2"><span class="bold">*Email:</span></div>
				<div class="grid6"><input type="text" maxlength="45" id="email" name="email" class="std-input"/></div>
				<div class="grid2"><span class="bold red hidden" id="email_error">Required field.</span></div>
				
				<div class="clrboth"></div>
				
				<div class="clrboth"></div>
				<div class="grid2" style="padding-top:30px;"><b>Security Code</b></div>
				<div class="grid6">
					<div class="grid2" style="margin-left:5px;"><?php echo newCaptcha(); ?></div>
					<div class="clrboth"></div>
					<input type="text" maxlength="6" id="captcha" name="captcha" class="std-input"/>
				</div>
				<div class="grid2"><span class="bold red hidden" id="captcha_error">Not match.</span></div>
				<input type="hidden" id="hdmd5capt" name="hdmd5capt" value="<?php echo md5($_SESSION['captcha']);?>" />
				
				<div class="clrboth"></div>
				<div class="grid2">&nbsp;</div>
				<div class="grid6"><input type="submit" class="submitclass" /> <?php echo loader_image('id="loader_image" class="hidden"');?></div>
				<div class="grid2"><span class="bold red hidden" id="submit_error">Missing registration.</span></div>	
				
				<div class="clrboth"></div>	
				
				<div class="grid2">&nbsp;</div>
				<div class="grid6" id="system_error"></div>

				<div class="clrboth"></div>		
			</div>	
			<div class="clrboth"></div>
		</div>
	</div>	
	<div class="clrboth"></div>
</div>	
</form>

<script type="text/javascript">
	google.setOnLoadCallback(function() {
		var option = { 
			beforeSubmit:  validateBeforeSubmit,  
			success: processAfterSubmit
		};	
		$('#forgot_details_submit').ajaxForm(option);
	});
	
	function validateBeforeSubmit(formData, jqForm, options){
		$('#loader_image').show();
		var field_arr = new Array( 'email_error' );
		for(i in field_arr){
			$('#'+field_arr[i]).hide();
		}
		var p = new PHP_JS();
		if(p.md5($('#captcha').val()) != $('#hdmd5capt').val()){
			$('#captcha_error').show();
			$('#loader_image').hide();
			return false;
		}
		return true;
	}
	
	function processAfterSubmit(responseText, statusText, xhr, $form){
		$('#loader_image').hide();
		var p = new PHP_JS();
		var result_arr = p.explode('#',responseText); 
		if(result_arr[0] == 'msg'){
			$('#system_error').html(result_arr[1]).show();
		}else if(result_arr[0] == 'err'){
			for(i in result_arr){
				$('#'+result_arr[i]).show();
			}
		}else if(result_arr[0] == 'ok'){
			queryURL(BASE_URI+MODULE+'/user/forgot_details_notify');
		}
	}
</script>